package com.cloudwise.monitoring_system.controller.mysqlController;

import com.cloudwise.monitoring_system.entity.MonitorUnit;
import com.cloudwise.monitoring_system.service.mysqlService.MonitorUnitService;

import com.cloudwise.monitoring_system.util.Result;
import com.cloudwise.monitoring_system.util.ReturnStatus;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * (MonitorUnit)表控制层
 *
 * @author makejava
 * @since 2021-05-28 10:53:33
 */
@Controller
@RequestMapping("monitorUnit")
@ApiOperation("mysql监控项unit菜单控制器")
public class MonitorUnitController {
    /**
     * 服务对象
     */
    @Resource
    private MonitorUnitService monitorUnitService;

    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @ResponseBody
    @GetMapping("queryAll")
    @ApiOperation("查询所有监控项")
    public Result queryAll(@ApiParam("监控项信息") MonitorUnit monitorUnit) {

        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),
                0,monitorUnitService.queryAll(monitorUnit));
    }

    /**
     * 新增数据
     *
     * @param monitorUnit 实例对象
     * @return 实例对象
     */
    @ResponseBody
    @PostMapping("insert")
    @ApiOperation("新增一条监控项")
    public Result insert(@ApiParam("监控项信息")MonitorUnit monitorUnit) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.monitorUnitService.insert(monitorUnit));
    }

    /**
     * 修改数据
     *
     * @param monitorUnit 实例对象
     * @return 实例对象
     */
    @ResponseBody
    @RequestMapping("update")
    @ApiOperation("修改监控项内容")
    public Result update(@ApiParam("监控项信息")MonitorUnit monitorUnit) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.monitorUnitService.update(monitorUnit));
    }

    /**
     * 通过主键删除数据
     *
     * @param monitorUnitId 主键
     * @return 是否成功
     */
    @ResponseBody
    @PostMapping("deleteById")
    @ApiOperation("删除监控项")
    public Result deleteById(@ApiParam("监控项unitId")Integer monitorUnitId) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.monitorUnitService.deleteById(monitorUnitId));
    }
}
